package MtG.client.panels;

import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JTextArea;

/**
 * MessagePanel.java is a class that is used for managing messages on a message panel.
 * @author Marek Sirp
 * @author Jaan Sepp
 */
public class MessagePanel extends JTextArea{
	
	/**
	 * Determines if a de-serialized file is compatible with this class.
	 */
	private static final long serialVersionUID = 3016792611609767781L;

	/**
	 * Constructor.
	 * @param message message to be added.
	 */
	public MessagePanel(String message){
		this.append(message);
		this.setEditable(false);
	}
	
	/**
	 * @param message text of the message to be added.
	 */
	public void addMessage(String message){
		String old = this.getText();
		this.setText(null);
		this.append(getTime() +" -> "+ message +"\n");
		this.append(old);
	}
	
	/**
	 * @return current time.
	 */
	private String getTime(){
		Calendar cal = new GregorianCalendar();
		String time = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" +  cal.get(Calendar.SECOND);
		return time;
	}
}
